{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Python Data Science with Pandas\n",
    "\n",
    "Agenda:\n",
    "1. Selecting and slicing data with loc and iloc\n",
    "2. Selecting data by value\n",
    "3. Selecting data from a time series by date and time values\n",
    "4. Applying and mapping functions to pandas dataframes and series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# magic command to display matplotlib plots inline within the ipython notebook webpage\n",
    "%matplotlib inline\n",
    "\n",
    "# import necessary modules\n",
    "import pandas as pd, numpy as np, matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Part 1 <br /> Basics of Selecting and Slicing Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Operation                       Syntax         Result\n",
    "#----------------------------------------------------------\n",
    "# Select column                   df[col]        Series\n",
    "# Select row by label             df.loc[label]  Series\n",
    "# Select row by integer location  df.iloc[loc]   Series\n",
    "# Slice rows                      df[5:10]       DataFrame\n",
    "# Select rows by boolean vector   df[bool_vec]   DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>lat</th>\n",
       "      <th>lon</th>\n",
       "      <th>date</th>\n",
       "      <th>city</th>\n",
       "      <th>country</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>51.481292</td>\n",
       "      <td>-0.451011</td>\n",
       "      <td>05/14/2014 09:07</td>\n",
       "      <td>West Drayton</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>51.474005</td>\n",
       "      <td>-0.450999</td>\n",
       "      <td>05/14/2014 09:22</td>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>51.478199</td>\n",
       "      <td>-0.446081</td>\n",
       "      <td>05/14/2014 10:51</td>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>51.478199</td>\n",
       "      <td>-0.446081</td>\n",
       "      <td>05/14/2014 11:24</td>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>51.474146</td>\n",
       "      <td>-0.451562</td>\n",
       "      <td>05/14/2014 11:38</td>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         lat       lon              date          city         country\n",
       "0  51.481292 -0.451011  05/14/2014 09:07  West Drayton  United Kingdom\n",
       "1  51.474005 -0.450999  05/14/2014 09:22      Hounslow  United Kingdom\n",
       "2  51.478199 -0.446081  05/14/2014 10:51      Hounslow  United Kingdom\n",
       "3  51.478199 -0.446081  05/14/2014 11:24      Hounslow  United Kingdom\n",
       "4  51.474146 -0.451562  05/14/2014 11:38      Hounslow  United Kingdom"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# create a pandas dataframe from the location data set\n",
    "df = pd.read_csv('data/summer-travel-gps-full.csv')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "With Python strings and lists, you can access individual elements inside the object by indexing or slicing with square brackets like my_list[0]. The same syntax works on pandas dataframes and series."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    West Drayton\n",
       "1        Hounslow\n",
       "2        Hounslow\n",
       "3        Hounslow\n",
       "4        Hounslow\n",
       "Name: city, dtype: object"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# get a column from the dataframe by its label with [] indexing - returns column as a pandas series with the dataframe's index\n",
    "df['city'].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can slice a pandas dataframe to grab multiple columns or rows at once, by their index, just like you can slice a list or a string. Here, we just pass a list of 2 column names in:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>city</th>\n",
       "      <th>country</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>West Drayton</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           city         country\n",
       "0  West Drayton  United Kingdom\n",
       "1      Hounslow  United Kingdom\n",
       "2      Hounslow  United Kingdom\n",
       "3      Hounslow  United Kingdom\n",
       "4      Hounslow  United Kingdom"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# get multiple columns by their labels by passing a list of column names within the [] operator - returns a dataframe\n",
    "df[['city', 'country']].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To get a single \"cell's\" value out of a dataframe, pass a column name, then a row label. This is equivalent to slicing the dataframe down to a single series, then slicing a single value out of that series using [ ] indexing."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'West Drayton'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# get a value using the [] operator for a column label then a row label\n",
    "df['city'][0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Using .loc[ ]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "lat                 51.4813\n",
       "lon               -0.451011\n",
       "date       05/14/2014 09:07\n",
       "city           West Drayton\n",
       "country      United Kingdom\n",
       "Name: 0, dtype: object"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# use .loc to select by row label - returns the row as a series whose index is the dataframe column labels\n",
    "df.loc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'United Kingdom'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# use .loc to select by row label and column label\n",
    "df.loc[0, 'country']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>city</th>\n",
       "      <th>date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>West Drayton</td>\n",
       "      <td>05/14/2014 09:07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Hounslow</td>\n",
       "      <td>05/14/2014 09:22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Hounslow</td>\n",
       "      <td>05/14/2014 10:51</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Hounslow</td>\n",
       "      <td>05/14/2014 11:24</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           city              date\n",
       "0  West Drayton  05/14/2014 09:07\n",
       "1      Hounslow  05/14/2014 09:22\n",
       "2      Hounslow  05/14/2014 10:51\n",
       "3      Hounslow  05/14/2014 11:24"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 0:3 is a slice of rows with label 0 to label 3\n",
    "# ['city', 'date'] is a list of column labels\n",
    "df.loc[0:3, ['city', 'date']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>city</th>\n",
       "      <th>country</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>05/14/2014 09:07</td>\n",
       "      <td>West Drayton</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>05/14/2014 09:22</td>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>05/14/2014 10:51</td>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>05/14/2014 11:24</td>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               date          city         country\n",
       "0  05/14/2014 09:07  West Drayton  United Kingdom\n",
       "1  05/14/2014 09:22      Hounslow  United Kingdom\n",
       "2  05/14/2014 10:51      Hounslow  United Kingdom\n",
       "3  05/14/2014 11:24      Hounslow  United Kingdom"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# slice by rows and columns\n",
    "df.loc[0:3, 'date':'country']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "West Drayton\n",
      "London\n"
     ]
    }
   ],
   "source": [
    "# you can set values with .loc as well\n",
    "print(df.loc[0, 'city'])\n",
    "df.loc[0, 'city'] = 'London'\n",
    "print(df.loc[0, 'city'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Using .iloc[ ]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'05/14/2014 11:24'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# use .iloc for integer position based indexing\n",
    "# get the value from the row in position 3 and the column in position 2\n",
    "df.iloc[3, 2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>city</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>112</th>\n",
       "      <td>05/16/2014 07:03</td>\n",
       "      <td>Lisbon</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>113</th>\n",
       "      <td>05/16/2014 07:33</td>\n",
       "      <td>Lisbon</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>114</th>\n",
       "      <td>05/16/2014 08:03</td>\n",
       "      <td>Lisbon</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 date    city\n",
       "112  05/16/2014 07:03  Lisbon\n",
       "113  05/16/2014 07:33  Lisbon\n",
       "114  05/16/2014 08:03  Lisbon"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# you can use .iloc with slices too\n",
    "# slice rows from position 112 to 115 and columns from position 2 to 4\n",
    "# iloc is not inclusive, so for example \"from 2 to 4\" will return positions 2 and 3 (but not 4)\n",
    "df.iloc[112:115, 2:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>lat</th>\n",
       "      <th>lon</th>\n",
       "      <th>date</th>\n",
       "      <th>city</th>\n",
       "      <th>country</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>51.481292</td>\n",
       "      <td>-0.451011</td>\n",
       "      <td>05/14/2014 09:07</td>\n",
       "      <td>London</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>300</th>\n",
       "      <td>41.377091</td>\n",
       "      <td>2.151175</td>\n",
       "      <td>05/20/2014 03:18</td>\n",
       "      <td>Barcelona</td>\n",
       "      <td>Spain</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>600</th>\n",
       "      <td>50.052338</td>\n",
       "      <td>19.946220</td>\n",
       "      <td>05/31/2014 21:10</td>\n",
       "      <td>Krakow</td>\n",
       "      <td>Poland</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>900</th>\n",
       "      <td>48.561181</td>\n",
       "      <td>9.059672</td>\n",
       "      <td>06/09/2014 15:12</td>\n",
       "      <td>Tübingen</td>\n",
       "      <td>Germany</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1200</th>\n",
       "      <td>41.378301</td>\n",
       "      <td>2.187443</td>\n",
       "      <td>06/17/2014 16:37</td>\n",
       "      <td>Barcelona</td>\n",
       "      <td>Spain</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1500</th>\n",
       "      <td>42.208201</td>\n",
       "      <td>20.735993</td>\n",
       "      <td>06/30/2014 08:27</td>\n",
       "      <td>Prizren</td>\n",
       "      <td>Kosovo</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            lat        lon              date       city         country\n",
       "0     51.481292  -0.451011  05/14/2014 09:07     London  United Kingdom\n",
       "300   41.377091   2.151175  05/20/2014 03:18  Barcelona           Spain\n",
       "600   50.052338  19.946220  05/31/2014 21:10     Krakow          Poland\n",
       "900   48.561181   9.059672  06/09/2014 15:12   Tübingen         Germany\n",
       "1200  41.378301   2.187443  06/17/2014 16:37  Barcelona           Spain\n",
       "1500  42.208201  20.735993  06/30/2014 08:27    Prizren          Kosovo"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# you can use iloc to select every nth row from a data set\n",
    "n = 300\n",
    "df.iloc[range(0, len(df), n)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>lat</th>\n",
       "      <th>lon</th>\n",
       "      <th>date</th>\n",
       "      <th>city</th>\n",
       "      <th>country</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>51.481292</td>\n",
       "      <td>-0.451011</td>\n",
       "      <td>05/14/2014 09:07</td>\n",
       "      <td>London</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>51.474005</td>\n",
       "      <td>-0.450999</td>\n",
       "      <td>05/14/2014 09:22</td>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>51.478199</td>\n",
       "      <td>-0.446081</td>\n",
       "      <td>05/14/2014 10:51</td>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>51.478199</td>\n",
       "      <td>-0.446081</td>\n",
       "      <td>05/14/2014 11:24</td>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>51.474146</td>\n",
       "      <td>-0.451562</td>\n",
       "      <td>05/14/2014 11:38</td>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          lat       lon              date      city         country\n",
       "0   51.481292 -0.451011  05/14/2014 09:07    London  United Kingdom\n",
       "1   51.474005 -0.450999  05/14/2014 09:22  Hounslow  United Kingdom\n",
       "4   51.478199 -0.446081  05/14/2014 10:51  Hounslow  United Kingdom\n",
       "9   51.478199 -0.446081  05/14/2014 11:24  Hounslow  United Kingdom\n",
       "16  51.474146 -0.451562  05/14/2014 11:38  Hounslow  United Kingdom"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# it's easier to tell the difference between .loc and .iloc if the index labels aren't the same as their positions\n",
    "df.index = [label**2 for label in df.index]\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>lat</th>\n",
       "      <th>lon</th>\n",
       "      <th>date</th>\n",
       "      <th>city</th>\n",
       "      <th>country</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>51.478199</td>\n",
       "      <td>-0.446081</td>\n",
       "      <td>05/14/2014 10:51</td>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>51.478199</td>\n",
       "      <td>-0.446081</td>\n",
       "      <td>05/14/2014 11:24</td>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         lat       lon              date      city         country\n",
       "4  51.478199 -0.446081  05/14/2014 10:51  Hounslow  United Kingdom\n",
       "9  51.478199 -0.446081  05/14/2014 11:24  Hounslow  United Kingdom"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# this returns the rows with labels between 4 and 9 (.loc is inclusive)\n",
    "df.loc[4:9]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>lat</th>\n",
       "      <th>lon</th>\n",
       "      <th>date</th>\n",
       "      <th>city</th>\n",
       "      <th>country</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>51.474146</td>\n",
       "      <td>-0.451562</td>\n",
       "      <td>05/14/2014 11:38</td>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>51.480146</td>\n",
       "      <td>-0.441103</td>\n",
       "      <td>05/14/2014 12:23</td>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>51.479669</td>\n",
       "      <td>-0.441024</td>\n",
       "      <td>05/14/2014 12:38</td>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>38.781775</td>\n",
       "      <td>-9.137544</td>\n",
       "      <td>05/14/2014 15:11</td>\n",
       "      <td>Lisbon</td>\n",
       "      <td>Portugal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>38.774422</td>\n",
       "      <td>-9.129195</td>\n",
       "      <td>05/14/2014 15:25</td>\n",
       "      <td>Lisbon</td>\n",
       "      <td>Portugal</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          lat       lon              date      city         country\n",
       "16  51.474146 -0.451562  05/14/2014 11:38  Hounslow  United Kingdom\n",
       "25  51.480146 -0.441103  05/14/2014 12:23  Hounslow  United Kingdom\n",
       "36  51.479669 -0.441024  05/14/2014 12:38  Hounslow  United Kingdom\n",
       "49  38.781775 -9.137544  05/14/2014 15:11    Lisbon        Portugal\n",
       "64  38.774422 -9.129195  05/14/2014 15:25    Lisbon        Portugal"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# this returns rows with labels in positions 4 through 8 (not through 9, because .iloc is not inclusive)\n",
    "df.iloc[4:9]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Part 2 <br /> How to select rows by some value(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>lat</th>\n",
       "      <th>lon</th>\n",
       "      <th>date</th>\n",
       "      <th>city</th>\n",
       "      <th>country</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>173</th>\n",
       "      <td>41.044556</td>\n",
       "      <td>28.983286</td>\n",
       "      <td>07/08/2014 16:44</td>\n",
       "      <td>Istanbul</td>\n",
       "      <td>Turkey</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>174</th>\n",
       "      <td>41.008992</td>\n",
       "      <td>28.968268</td>\n",
       "      <td>07/08/2014 20:03</td>\n",
       "      <td>Istanbul</td>\n",
       "      <td>Turkey</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>175</th>\n",
       "      <td>41.043487</td>\n",
       "      <td>28.985488</td>\n",
       "      <td>07/08/2014 22:18</td>\n",
       "      <td>Istanbul</td>\n",
       "      <td>Turkey</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>176</th>\n",
       "      <td>40.977637</td>\n",
       "      <td>28.823879</td>\n",
       "      <td>07/09/2014 09:03</td>\n",
       "      <td>Istanbul</td>\n",
       "      <td>Turkey</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>177</th>\n",
       "      <td>48.357110</td>\n",
       "      <td>11.791346</td>\n",
       "      <td>07/09/2014 13:20</td>\n",
       "      <td>Munich</td>\n",
       "      <td>Germany</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           lat        lon              date      city  country\n",
       "173  41.044556  28.983286  07/08/2014 16:44  Istanbul   Turkey\n",
       "174  41.008992  28.968268  07/08/2014 20:03  Istanbul   Turkey\n",
       "175  41.043487  28.985488  07/08/2014 22:18  Istanbul   Turkey\n",
       "176  40.977637  28.823879  07/09/2014 09:03  Istanbul   Turkey\n",
       "177  48.357110  11.791346  07/09/2014 13:20    Munich  Germany"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# load a reduced set of gps data\n",
    "df = pd.read_csv('data/summer-travel-gps-simplified.csv')\n",
    "df.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      False\n",
       "1      False\n",
       "2      False\n",
       "3      False\n",
       "4      False\n",
       "5      False\n",
       "6      False\n",
       "7      False\n",
       "8      False\n",
       "9      False\n",
       "10     False\n",
       "11     False\n",
       "12     False\n",
       "13     False\n",
       "14     False\n",
       "15     False\n",
       "16     False\n",
       "17     False\n",
       "18     False\n",
       "19     False\n",
       "20     False\n",
       "21     False\n",
       "22     False\n",
       "23     False\n",
       "24     False\n",
       "25     False\n",
       "26     False\n",
       "27     False\n",
       "28     False\n",
       "29     False\n",
       "       ...  \n",
       "148    False\n",
       "149    False\n",
       "150    False\n",
       "151    False\n",
       "152    False\n",
       "153    False\n",
       "154    False\n",
       "155    False\n",
       "156    False\n",
       "157    False\n",
       "158    False\n",
       "159    False\n",
       "160    False\n",
       "161    False\n",
       "162    False\n",
       "163    False\n",
       "164    False\n",
       "165    False\n",
       "166    False\n",
       "167    False\n",
       "168    False\n",
       "169    False\n",
       "170    False\n",
       "171    False\n",
       "172    False\n",
       "173    False\n",
       "174    False\n",
       "175    False\n",
       "176    False\n",
       "177     True\n",
       "Name: city, dtype: bool"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# create a Series of true/false, indicating if each row in the column is equal to some value\n",
    "df['city']=='Munich'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>lat</th>\n",
       "      <th>lon</th>\n",
       "      <th>date</th>\n",
       "      <th>city</th>\n",
       "      <th>country</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>177</th>\n",
       "      <td>48.35711</td>\n",
       "      <td>11.791346</td>\n",
       "      <td>07/09/2014 13:20</td>\n",
       "      <td>Munich</td>\n",
       "      <td>Germany</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          lat        lon              date    city  country\n",
       "177  48.35711  11.791346  07/09/2014 13:20  Munich  Germany"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# now, select only those rows in the df that match that condition\n",
    "df[df['city']=='Munich']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>lat</th>\n",
       "      <th>lon</th>\n",
       "      <th>date</th>\n",
       "      <th>city</th>\n",
       "      <th>country</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>41.303911</td>\n",
       "      <td>2.105931</td>\n",
       "      <td>05/18/2014 22:35</td>\n",
       "      <td>El Prat de Llobregat</td>\n",
       "      <td>Spain</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>41.289946</td>\n",
       "      <td>2.064590</td>\n",
       "      <td>05/18/2014 23:04</td>\n",
       "      <td>Viladecans</td>\n",
       "      <td>Spain</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>126</th>\n",
       "      <td>41.306752</td>\n",
       "      <td>2.097624</td>\n",
       "      <td>06/12/2014 17:19</td>\n",
       "      <td>El Prat de Llobregat</td>\n",
       "      <td>Spain</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>127</th>\n",
       "      <td>41.304333</td>\n",
       "      <td>2.072728</td>\n",
       "      <td>06/12/2014 17:49</td>\n",
       "      <td>El Prat de Llobregat</td>\n",
       "      <td>Spain</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>131</th>\n",
       "      <td>41.358460</td>\n",
       "      <td>2.128701</td>\n",
       "      <td>06/13/2014 11:35</td>\n",
       "      <td>Hospitalet de Llobregat</td>\n",
       "      <td>Spain</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>138</th>\n",
       "      <td>41.294761</td>\n",
       "      <td>2.059722</td>\n",
       "      <td>06/20/2014 22:15</td>\n",
       "      <td>Viladecans</td>\n",
       "      <td>Spain</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           lat       lon              date                     city country\n",
       "24   41.303911  2.105931  05/18/2014 22:35     El Prat de Llobregat   Spain\n",
       "25   41.289946  2.064590  05/18/2014 23:04               Viladecans   Spain\n",
       "126  41.306752  2.097624  06/12/2014 17:19     El Prat de Llobregat   Spain\n",
       "127  41.304333  2.072728  06/12/2014 17:49     El Prat de Llobregat   Spain\n",
       "131  41.358460  2.128701  06/13/2014 11:35  Hospitalet de Llobregat   Spain\n",
       "138  41.294761  2.059722  06/20/2014 22:15               Viladecans   Spain"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# pandas logical operators are: | for or, & for and, ~ for not\n",
    "# these must be grouped by using parentheses\n",
    "# what cities were visited in spain that were not barcelona?\n",
    "not_bcn = df[(df['country']=='Spain') & ~(df['city']=='Barcelona')]\n",
    "not_bcn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['El Prat de Llobregat', 'Viladecans', 'Hospitalet de Llobregat'], dtype=object)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "not_bcn['city'].unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>lat</th>\n",
       "      <th>lon</th>\n",
       "      <th>date</th>\n",
       "      <th>city</th>\n",
       "      <th>country</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>139</th>\n",
       "      <td>44.821164</td>\n",
       "      <td>20.289821</td>\n",
       "      <td>06/21/2014 01:59</td>\n",
       "      <td>Belgrade</td>\n",
       "      <td>Serbia</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>140</th>\n",
       "      <td>44.820414</td>\n",
       "      <td>20.463465</td>\n",
       "      <td>06/21/2014 18:44</td>\n",
       "      <td>Belgrade</td>\n",
       "      <td>Serbia</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>141</th>\n",
       "      <td>44.761583</td>\n",
       "      <td>19.577904</td>\n",
       "      <td>06/22/2014 07:58</td>\n",
       "      <td>Slepčević</td>\n",
       "      <td>Serbia</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>177</th>\n",
       "      <td>48.357110</td>\n",
       "      <td>11.791346</td>\n",
       "      <td>07/09/2014 13:20</td>\n",
       "      <td>Munich</td>\n",
       "      <td>Germany</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           lat        lon              date       city  country\n",
       "139  44.821164  20.289821  06/21/2014 01:59   Belgrade   Serbia\n",
       "140  44.820414  20.463465  06/21/2014 18:44   Belgrade   Serbia\n",
       "141  44.761583  19.577904  06/22/2014 07:58  Slepčević   Serbia\n",
       "177  48.357110  11.791346  07/09/2014 13:20     Munich  Germany"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# select rows where either the city is munich, or the country is serbia\n",
    "df[(df['city']=='Munich') | (df['country']=='Serbia')]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "24"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# how many observations are west of the prime meridian?\n",
    "len(df[df['lon'] < 0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>lat</th>\n",
       "      <th>lon</th>\n",
       "      <th>date</th>\n",
       "      <th>city</th>\n",
       "      <th>country</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>50.273632</td>\n",
       "      <td>18.729429</td>\n",
       "      <td>06/02/2014 06:39</td>\n",
       "      <td>Gliwice</td>\n",
       "      <td>Poland</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>114</th>\n",
       "      <td>48.282940</td>\n",
       "      <td>8.199630</td>\n",
       "      <td>06/10/2014 13:33</td>\n",
       "      <td>Gutach</td>\n",
       "      <td>Germany</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>115</th>\n",
       "      <td>48.389029</td>\n",
       "      <td>8.021342</td>\n",
       "      <td>06/10/2014 13:48</td>\n",
       "      <td>Gengenbach</td>\n",
       "      <td>Germany</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>152</th>\n",
       "      <td>40.187825</td>\n",
       "      <td>20.079303</td>\n",
       "      <td>07/04/2014 17:42</td>\n",
       "      <td>Gjirokastër</td>\n",
       "      <td>Albania</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           lat        lon              date         city  country\n",
       "62   50.273632  18.729429  06/02/2014 06:39      Gliwice   Poland\n",
       "114  48.282940   8.199630  06/10/2014 13:33       Gutach  Germany\n",
       "115  48.389029   8.021342  06/10/2014 13:48   Gengenbach  Germany\n",
       "152  40.187825  20.079303  07/04/2014 17:42  Gjirokastër  Albania"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# get all rows that contain a city that starts with the letter G\n",
    "row_mask = df['city'].str.startswith('G')\n",
    "df[row_mask]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>lat</th>\n",
       "      <th>lon</th>\n",
       "      <th>date</th>\n",
       "      <th>city</th>\n",
       "      <th>country</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>41.237205</td>\n",
       "      <td>-8.672173</td>\n",
       "      <td>05/18/2014 19:55</td>\n",
       "      <td>Maia</td>\n",
       "      <td>Portugal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>142</th>\n",
       "      <td>43.859459</td>\n",
       "      <td>18.425962</td>\n",
       "      <td>06/22/2014 21:12</td>\n",
       "      <td>Sarajevo</td>\n",
       "      <td>Bosnia and Herzegovina</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>143</th>\n",
       "      <td>43.858562</td>\n",
       "      <td>18.397478</td>\n",
       "      <td>06/23/2014 14:12</td>\n",
       "      <td>Sarajevo</td>\n",
       "      <td>Bosnia and Herzegovina</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151</th>\n",
       "      <td>40.702184</td>\n",
       "      <td>19.946288</td>\n",
       "      <td>07/04/2014 08:14</td>\n",
       "      <td>Berat</td>\n",
       "      <td>Albania</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>177</th>\n",
       "      <td>48.357110</td>\n",
       "      <td>11.791346</td>\n",
       "      <td>07/09/2014 13:20</td>\n",
       "      <td>Munich</td>\n",
       "      <td>Germany</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           lat        lon              date      city                 country\n",
       "23   41.237205  -8.672173  05/18/2014 19:55      Maia                Portugal\n",
       "142  43.859459  18.425962  06/22/2014 21:12  Sarajevo  Bosnia and Herzegovina\n",
       "143  43.858562  18.397478  06/23/2014 14:12  Sarajevo  Bosnia and Herzegovina\n",
       "151  40.702184  19.946288  07/04/2014 08:14     Berat                 Albania\n",
       "177  48.357110  11.791346  07/09/2014 13:20    Munich                 Germany"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# select all rows with certain city names by using .isin([list])\n",
    "row_mask = df['city'].isin(['Munich', 'Berat', 'Maia', 'Sarajevo'])\n",
    "df[row_mask]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Part 3 <br /> How to select based on a date-time values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>lat</th>\n",
       "      <th>lon</th>\n",
       "      <th>city</th>\n",
       "      <th>country</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2014-05-14 09:07:00</th>\n",
       "      <td>51.481292</td>\n",
       "      <td>-0.451011</td>\n",
       "      <td>West Drayton</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2014-05-14 09:22:00</th>\n",
       "      <td>51.474005</td>\n",
       "      <td>-0.450999</td>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2014-05-14 10:51:00</th>\n",
       "      <td>51.478199</td>\n",
       "      <td>-0.446081</td>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2014-05-14 11:24:00</th>\n",
       "      <td>51.478199</td>\n",
       "      <td>-0.446081</td>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2014-05-14 11:38:00</th>\n",
       "      <td>51.474146</td>\n",
       "      <td>-0.451562</td>\n",
       "      <td>Hounslow</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                           lat       lon          city         country\n",
       "date                                                                  \n",
       "2014-05-14 09:07:00  51.481292 -0.451011  West Drayton  United Kingdom\n",
       "2014-05-14 09:22:00  51.474005 -0.450999      Hounslow  United Kingdom\n",
       "2014-05-14 10:51:00  51.478199 -0.446081      Hounslow  United Kingdom\n",
       "2014-05-14 11:24:00  51.478199 -0.446081      Hounslow  United Kingdom\n",
       "2014-05-14 11:38:00  51.474146 -0.451562      Hounslow  United Kingdom"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# load the location data set, indexed by the date field\n",
    "# and, parse the dates so they're no longer strings but now rather Python datetime objects\n",
    "# this lets us do date and time based operations on the data set\n",
    "dt = pd.read_csv('data/summer-travel-gps-full.csv', index_col='date', parse_dates=True)\n",
    "dt.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1759"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(dt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1759 rows - but is the timestamp index unique?\n",
    "dt.index.is_unique"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1750"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# the index is not unique - drop duplicates\n",
    "dt.drop_duplicates(inplace=True)\n",
    "len(dt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 0, 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, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]'"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# the .weekday attribute determines which day of the week a date is\n",
    "# 0 is sunday and 6 is saturday, M-F are 1-5\n",
    "# what day of the week is each datetime in our dataframe's index?\n",
    "str(list(dt.index.weekday))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([False, False, False, ..., False, False, False], dtype=bool)"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# use bitwise OR to create a boolean vector of which rows are a weekend date\n",
    "weekend_mask = (dt.index.weekday==6) | (dt.index.weekday==0)\n",
    "weekend_mask"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "weekends = dt[weekend_mask]\n",
    "weekdays = dt[~weekend_mask]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x1a63b4f8470>"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
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FmdGvXz9GjhxZ2+sxefJkfvGLX1BY\nWEi7du0YN24cjz32WO1z7N27l1tvvZVFixZRUVFB586dAZgzZw5XXXUVRx11FIcccgiJ97gZNGgQ\nRx99NADHHHMMF198MUuWLAFg+PDhrF27lrfffhuAGTNmcNFFF3HggXk36iYiInlIvzbNMHjwYBYv\nXsy6desoKyujU6dOVFRU8MILLzB48GCqqqpYtmxZbcLg7uzZs4dRo0axdetWdu7cyfHHH18bb+/e\nvXXmamzfvp3Jkycze/Zs2rdvX1u+ceNGTjjhhNr1kpKSOvstX76cO+64g9dff51du3axa9cuLrjg\nAgDatGnDRRddxIwZM/jxj3/MY489xhNPPJG1YyQiIhJPiUczDBo0iKeffppYLMadd95JYWEhM2fO\nZNmyZdx4441UVlZSVlbGs88+u8++7k7btm1544036Nq1a9L4nTt3ZsaMGVxwwQU8+eSTnHzyyQB0\n7dqVDRs21NarqqqqM8fjO9/5DjfddBPPPvssBx10EN/73vf44IMParePGjWKyy+/nG9961u0a9eO\nk046KVOHRESaKNmZerl0dp1IpmmopRlqejw+++wzioqKGDhwIAsXLuSDDz7guOOO45xzzqGyspIZ\nM2bwxRdfsHv3bl566SXeeustzIxrrrmGW265ha1btwJQXV1NeXl5necYNGgQM2fO5Pzzz2fFihUA\nXHjhhUydOpXVq1ezc+fOfeaFfPrpp3Tq1ImDDjqIF198kUcffbTO9gEDBlBQUMCtt97K5ZdfnsUj\nJCKNqTlTL37J5iUDRFqaEo9m6NOnDx06dGDQoEEAdOjQgV69enHKKadgZrRv357y8nJmzZpFUVER\nRUVFjBs3rvbMlXvvvZfevXszYMAAOnbsyJAhQ6isrNzneU4//XSmTJnC8OHDWblyJUOHDuWWW27h\n1FNPpW/fvpx22ml16j/44IP86Ec/orCwkJ/85Cd1zrapMWrUKF5//XUuu+yyLBwZERGR5PLu7rSt\n6QJi2TR9+nQmT57M0qVLG62ru9OKZE///ufuc22i6upzefnl7F2vKBfU913enO/gbMSU9NV3d9q8\nm+OhD0/z7dy5kw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uEvzS+T958DHYD1zXyP3gO+T5DUvEM49y7clu6w3Y3he38qwRDTrwiG\nVScA09OMuU8CSDAcPBR4JM2YLxD0ul1AkMSfF5YPBl5KM+bfa77jgeEEc+JqtjU52Sbo6bmP4I+B\njwh6NleHZekOr30bOKKebeelGfO/gNOTlA8l/cvP3004jSChvDfwh3RiuudB4qFFi5b0l4QvzQ8T\nvjQ7pRmzVX9pxsUZTjB34P1mxrkrYamZK3U4MK0ZccuA2QRznF4DFgDXEvaEpBFvViY+kwkx+xHM\noXgGODJMkLYTJJwnpxnzX4AXwyThecI/PAh6Dm9KM+aRwOmJnyfS7HmPi3laRDGH5VQ7M/1B0qJF\nS34shEM5itmsOIcAx+R6OxUz/ZgEQ6lvAX8kGF4eEbct3WHAbMS8MR9iuntun04rItljZu+6ew/F\nVEzFbHCf14BvuvunZlZKcHr/dHf/lZm94u7HpdGOVhsTyPmzWkSkGbJxFpdiKmYri5mNsxZbc0wl\nHiL7uS4EpxV+lFBuBJPwFFMxFbNhm83sWHdfCRD+9X8O8DvgG2m2sTXHVOIhsp+bTzApbGXiBjOr\nUEzFVMxGjQLqXJfI3b8ARplZWrfYaOUxNcdDREREopPPd6cVERGRPKPEQ0RERCKjxENEREQio8RD\nREREIqPEQ0RERCLz/wHGBZUU5yr2YAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1a63b5009b0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "hourly_share = pd.DataFrame()\n",
    "\n",
    "# calculate what share of the weekday observations each hour has\n",
    "weekday_hourly = weekdays.groupby(weekdays.index.hour).size()\n",
    "hourly_share['weekday'] = weekday_hourly / sum(weekday_hourly)\n",
    "\n",
    "# calculate what share of the weekend observations each hour has\n",
    "weekend_hourly = weekends.groupby(weekends.index.hour).size()\n",
    "hourly_share['weekend'] = weekend_hourly / sum(weekend_hourly)\n",
    "\n",
    "# format the x-axis ticks like 0:00 times and plot the data\n",
    "hourly_share.index = [s + ':00' for s in hourly_share.index.astype(str)]\n",
    "hourly_share.plot(figsize=[9, 4], kind='bar', stacked=False, alpha=0.7, title='Share of observations, by hour')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x1a63b53fcc0>"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAeMAAAFyCAYAAADGTbLeAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XucJGV97/HPFxERuWqUFVDAgIAoqEeIqNFRI5qgQmJE\nVBRFjSfGxKM55wiemF0vibfoydVjVEQ0IqDGoIkiEhgQFVBARUAlRhCBJUHwAhoB+Z0/qoZthrks\nOzv9zEx93q9Xv7a6uqvr9/T09rfqqaeqU1VIkqR2NmldgCRJQ2cYS5LUmGEsSVJjhrEkSY0ZxpIk\nNWYYS5LUmGGsppIcm+SNjdd/fZJz7uJyOye5Lcmy+j+U5HlJTmm4/kV735I8IcmVG/t112O9v53k\n+0l+kmTfBus/IskXxr1ebVzL6otEiy/J5UmuTXLPkXkvSXJGy7oWQ5LHAU8GdqiqR2/ASyzpk/Rn\nCr6qOr6qntayLhb3fWvxN3kH8Iqq2rqqvt5g/bDEP4uan2Gs6Yruc/E/Zpi/pG3A3tYuwOVV9V+L\nUM5GkSQLWZzu77aQ19D8dgYuaV2EljfDWDN5B/DHSbae/sBMe1tJzkhyZD99RJKzk7wryQ1J/i3J\nAf387ydZm+SF0172vklO7bv5zkjywJHX3rN/7IdJLk3y7JHHjk3y7iT/kuSnwMQM9d4/ycn98t9J\n8tJ+/pHA+4AD+vWunmHZJPmTvrdgbZIPTntPArwkyVX97Y9Hlt0vyVeS/DjJNUn+YuSxRyf5Yv/+\nXJjkCdPeyzf37+FN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kL3hjG0gD0o6ofBexRVQ/uz7f8WFU9tnFp\ni8bBe1pONmldgKSx+G3gmfSnuFXV1cBWTStafA7e07JhGEvDcHN/5bkCSHKvxvUsOgfvaTkxjKVh\nOCnJ3wPbJnkZcBrwvsY1Sep5zFhawZL8D+BLwAV0v1pzIN3o4s9V1edb1iZpHU9tkla2nYC/BPYE\nLgK+SBfO58+1kKTxcs9YGoAkm9GNpn4McEB/+1FVPaRpYZIA94ylobgnsDWwTX+7mm5PWdIS4J6x\ntIIleS+wN/BT4FzgHOCcqrqhaWGS7sDR1NLK9kDgHsBa4CrgB8CPmlYk6U7cM5ZWuCSh2zt+TH97\nKHA98OWqWj3XspLGwzCWBiLJTsBj6QL56cB9qmrbtlVJAsNYWtGS/BHr9ohvoTutaep2UVXd1rA8\nST1HU0sr2y7Ax4BXV9U1jWuRNAv3jCVJaszR1JIkNWYYS5LUmGEsSVJjhrEkSY39f4etKKkDbwiP\nAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1a63b5e0fd0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# calculate and plot the number of observations each day of the week has\n",
    "daily_count = dt.groupby(dt.index.weekday).size()\n",
    "daily_count.index = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']\n",
    "daily_count.plot(figsize=[8, 5], kind='bar', title='Number of observations, by day of week')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "# Part 4 <br /> map(), apply(), and applymap() in pandas\n",
    "\n",
    "These methods are useful for mapping/applying a function across elements, rows, and columns of a pandas DataFrame or Series. But they have some important and often confusing differences.\n",
    "\n",
    "1. map() applies a function element-wise on a Series\n",
    "2. apply() works on a row or column basis on a DataFrame (specify the axis!), or on a row basis on a Series\n",
    "3. applymap() works element-wise on an entire DataFrame\n",
    "\n",
    "Let's see what that means in practice with some examples."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>end_year</th>\n",
       "      <th>start_year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2002</td>\n",
       "      <td>2001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2010</td>\n",
       "      <td>2002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2008</td>\n",
       "      <td>2005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2006</td>\n",
       "      <td>2005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2014</td>\n",
       "      <td>2006</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   end_year  start_year\n",
       "0      2002        2001\n",
       "1      2010        2002\n",
       "2      2008        2005\n",
       "3      2006        2005\n",
       "4      2014        2006"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# create a new DataFrame with fake year data\n",
    "df = pd.DataFrame({'start_year':[2001, 2002, 2005, 2005, 2006], \n",
    "                   'end_year':[2002, 2010, 2008, 2006, 2014]})\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2001\n",
      "2002\n",
      "2015\n",
      "2015\n",
      "2016\n"
     ]
    }
   ],
   "source": [
    "# you can iterate through a DataFrame using the .iterrows() method\n",
    "for _, row in df.iterrows():\n",
    "    start_year = row['start_year']\n",
    "    if start_year > 2004:\n",
    "        print(start_year + 10)\n",
    "    else:\n",
    "        print(start_year)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### alternatively, .map() applies a function element-wise on a Series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    2001\n",
       "1    2002\n",
       "2    2015\n",
       "3    2015\n",
       "4    2016\n",
       "Name: start_year, dtype: int64"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# create a function\n",
    "def get_new_year(x):\n",
    "    if x > 2004:\n",
    "        return x + 10\n",
    "    else:\n",
    "        return x\n",
    "\n",
    "# then map it to the series\n",
    "df['start_year'].map(get_new_year)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    2001\n",
       "1    2002\n",
       "2    2015\n",
       "3    2015\n",
       "4    2016\n",
       "Name: start_year, dtype: int64"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# or do the same thing all in one line, using a lambda function as .map()'s argument... you commonly see this in pandas\n",
    "df['start_year'].map(lambda x: x + 10 if x > 2004 else x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A [lambda function](http://www.python-course.eu/lambda.php) is a simple, one-off, anonymous function. You can't call it again later because it doesn't have a name. It just lets you repeatedly perform some operation across a series of values (in our case, a column in our dataframe) using a minimal amount of code. Also notice that the if-else statement is all on one line: this is called a [ternary operator](http://pythoncentral.io/one-line-if-statement-in-python-ternary-conditional-operator/) or an inline-if."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>end_year</th>\n",
       "      <th>start_year</th>\n",
       "      <th>new_year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2002</td>\n",
       "      <td>2001</td>\n",
       "      <td>2001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2010</td>\n",
       "      <td>2002</td>\n",
       "      <td>2002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2008</td>\n",
       "      <td>2005</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2006</td>\n",
       "      <td>2005</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2014</td>\n",
       "      <td>2006</td>\n",
       "      <td>2016</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   end_year  start_year  new_year\n",
       "0      2002        2001      2001\n",
       "1      2010        2002      2002\n",
       "2      2008        2005      2015\n",
       "3      2006        2005      2015\n",
       "4      2014        2006      2016"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# you can easily create a new column to contain the results of the function mapping\n",
    "df['new_year'] = df['start_year'].map(get_new_year)\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### .apply() is like .map(), but it works on a row or column basis on an entire DataFrame (specify the axis)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "end_year      12\n",
       "start_year     5\n",
       "new_year      15\n",
       "dtype: int64"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# applies a function to calculate the difference between the min and max values in each column (ie, row-wise)\n",
    "def get_difference(vector):\n",
    "    difference = vector.max() - vector.min()\n",
    "    return difference\n",
    "\n",
    "df.apply(get_difference, axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "end_year      12\n",
       "start_year     5\n",
       "new_year      15\n",
       "dtype: int64"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# same thing again, using a lambda function\n",
    "df.apply(lambda x: x.max() - x.min(), axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>end_year</th>\n",
       "      <th>start_year</th>\n",
       "      <th>new_year</th>\n",
       "      <th>difference</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2002</td>\n",
       "      <td>2001</td>\n",
       "      <td>2001</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2010</td>\n",
       "      <td>2002</td>\n",
       "      <td>2002</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2008</td>\n",
       "      <td>2005</td>\n",
       "      <td>2015</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2006</td>\n",
       "      <td>2005</td>\n",
       "      <td>2015</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2014</td>\n",
       "      <td>2006</td>\n",
       "      <td>2016</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   end_year  start_year  new_year  difference\n",
       "0      2002        2001      2001           1\n",
       "1      2010        2002      2002           8\n",
       "2      2008        2005      2015          10\n",
       "3      2006        2005      2015          10\n",
       "4      2014        2006      2016          10"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# here .apply() finds the difference between the min and max values in each row (ie, column-wise) and saves to a new column\n",
    "df['difference'] = df.apply(get_difference, axis=1)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### .applymap() works element-wise on an entire DataFrame\n",
    "This is like doing a .map() to each column in the DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>end_year</th>\n",
       "      <th>start_year</th>\n",
       "      <th>new_year</th>\n",
       "      <th>difference</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1001.0</td>\n",
       "      <td>1000.5</td>\n",
       "      <td>1000.5</td>\n",
       "      <td>0.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1005.0</td>\n",
       "      <td>1001.0</td>\n",
       "      <td>1001.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1004.0</td>\n",
       "      <td>1002.5</td>\n",
       "      <td>1007.5</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1003.0</td>\n",
       "      <td>1002.5</td>\n",
       "      <td>1007.5</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1007.0</td>\n",
       "      <td>1003.0</td>\n",
       "      <td>1008.0</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   end_year  start_year  new_year  difference\n",
       "0    1001.0      1000.5    1000.5         0.5\n",
       "1    1005.0      1001.0    1001.0         4.0\n",
       "2    1004.0      1002.5    1007.5         5.0\n",
       "3    1003.0      1002.5    1007.5         5.0\n",
       "4    1007.0      1003.0    1008.0         5.0"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# divide every value in the dataframe by 2 (use a float so you don't do rounded integer division)\n",
    "df.applymap(lambda x: x / 2.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
